var BaseFun = require('../../../Base/server/controllers/Function');

module.exports.deleteLogField = function(){
	var nowDate = new Date();
	nowDate.setDate(nowDate.getDate() - 7);

	var fileName = nowDate.getFullYear() +
    '.' + (nowDate.getMonth() + 1 < 10 ? '0' + (nowDate.getMonth() + 1).toString() : (nowDate.getMonth() + 1).toString()) +
    '.' + (nowDate.getDate() < 10 ? '0' + nowDate.getDate().toString() : nowDate.getDate().toString());

    var deleteFile = function(fileName){
    	return new Promise(function(resolve, reject) {
	    	BaseFun.fileDelete(fileName, function(data, err){
	    		if(err){
	    			reject(err);
	    		}
	    		else{
	    			resolve(data);
	    		}
	    	});
	    });
    };
    var promises = [];
    promises.push(deleteFile('./logs/error/' + fileName + '.log'));
    promises.push(deleteFile('./logs/access/' + fileName + '.log'));
    promises.push(deleteFile('./logs/execute/' + fileName + '.log'));
    return Promise.all(promises);
};
